package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.VO.OperatorVO;
import com.company.project.model.VtManager;
import com.company.project.model.VtOperator;
import com.company.project.service.VtManagerService;
import com.company.project.service.VtOperatorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2023/10/20.
*/
@RestController
@RequestMapping("/vt/operator")
public class VtOperatorController {
    @Resource
    private VtOperatorService vtOperatorService;

    @Resource
    private VtManagerService vtManagerService;

    @PostMapping("/add")
    public Result add(VtOperator vtOperator) {
        vtOperatorService.save(vtOperator);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        vtOperatorService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(VtOperator vtOperator) {
        vtOperatorService.update(vtOperator);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        VtOperator vtOperator = vtOperatorService.findById(id);
        return ResultGenerator.genSuccessResult(vtOperator);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<VtOperator> list = vtOperatorService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @PostMapping("/operatorList")
    public Result operatorList(@RequestParam Integer groupId) {
        List<OperatorVO> vtManagers = vtManagerService.findOprator(groupId);

        return ResultGenerator.genSuccessResult(vtManagers);
    }

    @PostMapping("/operatorAllList")
    public Result operatorAllList() {
        List<OperatorVO> vtManagers = new ArrayList<>();
        for (int i = 13; i < 16; i++) {
            vtManagers.addAll(vtManagerService.findOprator(i));
        }
        return ResultGenerator.genSuccessResult(vtManagers);
    }
}
